# dockerfile.ubuntu.ssh.txt.sh
# dockerfile ubuntu ssh
# By Elvin , 2024

FROM ubuntu:focal

RUN date ; \
    export DEBIAN_FRONTEND=noninteractive ; \
    # #use aliyun source,and install#
    # sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list && \
    # sed -i 's/security.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list && \
    apt-get update  && \
    apt install -y net-tools && \
    \
    #time zone
    apt install -y tzdata ; \
    rm -f /etc/localtime ; \
    ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ; \
    dpkg-reconfigure --frontend noninteractive tzdata ; \
    date ; \
    \
    #ssh-server
    apt-get install -y openssh-server openssh-client && \
    mkdir -p /var/run/sshd /run/sshd && \
    sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/'  /etc/ssh/sshd_config && \
    sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \
    sed -ir '3 iGSSAPIAuthentication no\nUseDNS no\n' /etc/ssh/sshd_config && \
    echo  'root:root' | chpasswd ; \
    \
    #start shell
    echo '#!/bin/bash'>/start.sh && \
    echo 'echo "root:${PSWD:-root}" | chpasswd' >>/start.sh && \
    echo '/usr/sbin/sshd -D -f /etc/ssh/sshd_config' >>/start.sh && \
    chmod +x /start.sh ; \
    \
    #clean
    apt-get clean  && \
    find /var/log/ -type f |xargs rm -f && \
    rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* 

CMD ["/start.sh"]


# docker build --no-cache -t ubuntu:ssh -f dockerfile.ubuntu.ssh.txt.sh .

#registry.cn-hangzhou.aliyuncs.com/elvin/ubuntu:ssh
